<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>智能表单-代码生成</title>
<t:base type="jquery,easyui,tools"></t:base>
<script type="text/javascript" src="plug-in/cgform/js/cgformField.js"></script>
<script type="text/javascript" src="plug-in/cgform/js/fileTree.js"></script>
<script type="text/javascript" src="plug-in/jquery-model.js"></script>
<script type="text/javascript">
function browseFolder(path) {
    try {
        var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息
        var Shell = new ActiveXObject("Shell.Application");
        var Folder = Shell.BrowseForFolder(0, Message, 64, 17); //起始目录为：我的电脑
        if (Folder != null) {
            Folder = Folder.items(); // 返回 FolderItems 对象
            Folder = Folder.item(); // 返回 Folderitem 对象
            Folder = Folder.Path; // 返回路径
            if (Folder.charAt(Folder.length - 1) != "\\") {
                Folder = Folder + "\\";
            }
            document.getElementById(path).value = Folder;
            return Folder;
        }
    }
    catch (e) {
        alert(e.message);
    }
   }
   
</script>
<style type="text/css">
.table-list {
	margin: 0;
	width: auto;
	margin-left: 0px;
	margin-right: 0px;
	overflow: hidden;
}

.table-list td,.table-list th {
	text-align: center;
}

.t_table {
	overflow: auto; /*让内容表格外面的div自动有滚动条*/
	margin-left: 0px;
	margin-right: 0px;
	width: auto;
	max-height: 240px;
}
</style>
</head>
<body style="overflow-y: scroll;" scroll="no">
<t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table" tiptype="1" action="generateController.do?dogenerate">
	<div style="text-align: center">
		<input type="submit" value="提交">
	</div>
	<input id="ids" name="ids" type="hidden" value="${ids}">
	<input type="hidden" id="fieldRowNum" name="fieldRowNum" value="1">
	<table cellpadding="0" cellspacing="1" class="formtable">
		<tr>
			<td align="right"><label class="Validform_label">代码生成目录: </label></td>
			<td class="value"><input type="text" class="inputxt" value="${projectPath }" name="projectPath" id="projectPath" datatype="*" />
				<a href="#" id="openFoldSelect" class="easyui-linkbutton"
				   icon="icon-search" onclick="openFolder('projectPath')">浏览</a>
			</td>
		</tr>
		<tr>
			<td align="right"><label class="Validform_label">UI生成目录: </label></td>
			<td class="value"><input type="text" class="inputxt" value="${uiPath }" name="uiPath" id="uiPath" datatype="*" />
				如:ui/page 左右两边无需 /
			</td>
		</tr>
		<tr>
			<td align="right"><label class="Validform_label">controller访问前缀: </label></td>
			<td class="value"><input type="text" class="inputxt" value="${controllerPrefix }" name="controllerPrefix" id="controllerPrefix" />
				如:sys 会生成 /sysTest
			</td>
		</tr>
		<tr>
			<td align="right"><label class="Validform_label">代码分层风格: </label></td>
			<td class="value"><select name="packageStyle">
				<option value="service">业务分层</option>
				<option value="project">代码分层</option>
			</select>
			</td>
		</tr>


		<tr>
			<td align="right"><label class="Validform_label"> 页面风格: </label></td>
			<td class="value" colspan="3">
			<select id="jspMode" name="jspMode">
		     		<c:forEach items="${jspModeList }" var="style">
			     	 <option value="${style.code }" >${style.desc }(${style.engineType.displayName})</option>
			     	</c:forEach>
		     </select>
			<span class="Validform_checktip"></span></td>
		</tr>
		<tr>
			<td align="right"><label class="Validform_label"> 模版引擎: </label></td>
			<td class="value" colspan="3">
				<select id="engineType" name="engineType">
					<c:forEach items="${templateTypes }" var="ttype">
						<option value="${ttype.name()}" >${ttype.displayName }</option>
					</c:forEach>
				</select>
				<span class="Validform_checktip"></span></td>
		</tr>
	</table>

</t:formvalid>
<div style="display: none;" id="tmp">
	<div>
		<input class="output" checked="checked" type="checkbox" value="{id}" name="outputTemplates"><i><b>{iterateOutput}{items}</b></i>📃{templatePath}</input>
		<div>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;目标路径:{fileNameTemplate}
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		</div>
	</div>
</div>
<script type="text/javascript">
	function getTemplateFileList() {
		var mo=$('#jspMode').find('option:checked')[0].value;
		$.ajax({
			url:'generateController.do?getTemplateFileList&templateDir='+mo,
            dataType:'json',
			success:function(data){
			    if (data && data.templateDefines){
			        $.each((data.templateDefines),function(i,v){
			            if (v.output){
                            var tmp=$('#tmp').lkqmodel({
								data:v,
                                formatter:function (data,key,value) {
									if (key=='iterateOutput'){
									    if (value){
									        return '循环输出';
										}else{
									        return '';
										}
									}else if(key=='items'){
                                        if (value){
                                            return ',♻️'+value;
                                        }else{
                                            return '';
                                        }
									}else{
									    return value;
									}
                                }
							});
                            $("#select").append(tmp);
                        }
					});
				}
			}
		});
    }


	$(function () {
		//获取模版列表文件
        getTemplateFileList();
    })
</script>
</body>